module TitlesHelper
  def options_feudal_titles (character = player_character, selected = "")
    return nil unless character
    hash = Hash.new
    character.titles.each do |title|
      if title.feudal? && !title.lord?
        hash[title.id] = title.name
      end
    end
    options_hash_select hash, selected
  end
  
  def options_title_categories_and_sub_categories (selected = "", excluded = {"1:1" => true, "1:2" => true, "1:7" => true, "2:1" => true, "2:5" => true})
    map = Hash.new
    max = Title.categories.size
    x = 1
    while x <= max do
      subcategories = Title.sub_categories(x)
      subcategories.each do |key, subcat|
        map["#{x}:#{key}"] = subcat["male"] unless excluded["#{x}:#{key}"]
      end
      x += 1
    end
    options_hash_select map.sort, selected
  end
  
  def options_title_categories (selected = 0)
    options_hash_select Title.categories selected
  end
  
  def options_title_subcategories (category, selected = 0)
    hash = Hash.new
    Title.sub_categories(category).each do |key, value|
      hash[key] = value["male"]
    end
    options_hash_select hash, selected
  end
  
  def link_title (title)
    return "None" unless title
    link = "#{title.sub_category_name}"
    if title.territory and title.territory > 0
      link += " of " + link_to_record (title.domain)
    end
    return link
  end
  
end
